package main

import (
	"flag"
	"fmt"
	"go.uber.org/zap"
	"google.golang.org/grpc"
	"net"
	"pm_back_server/project-server/handler"
	"pm_back_server/project-server/initialize"
	"pm_back_server/project-server/proto"
)

func main() {
	IP := flag.String("ip", "0.0.0.0", "ip地址")
	Port := flag.Int("port", 50052, "port端口号")

	// 初始化配置
	initialize.InitConfig()
	// 初始化日志
	initialize.InitLogger()
	// 初始化数据库
	initialize.InitDB()

	flag.Parse()
	zap.S().Info("ip: ", *IP)
	zap.S().Info("port: ", *Port)

	server := grpc.NewServer()
	proto.RegisterProjectServer(server, &handler.ProjectServer{})

	lis, err := net.Listen("tcp", fmt.Sprintf("%s:%d", *IP, *Port))
	if err != nil {
		zap.S().Panicw("监听端口失败: ", err.Error())
	}

	err = server.Serve(lis)
	if err != nil {
		zap.S().Panicw("启动GRPC失败: ", err.Error())
	}
}
